package com.trace.pplos.parse.dao.dataobject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

public class WpxxInfo {
    private static final Logger logger = LoggerFactory.getLogger(WpxxInfo.class);

    private Integer id;

    private String billNo;

    private String types;

    private String name;

    private String nos;

    private String addr;

    private String lng;

    private String lat;

    private String des;

    private String photoPath;

    private String synced;

    private String lngGps;

    private String latGps;

    private String cjdw;

    private String filepath;

    private Date gmtCreate;

    private String gmtCreateUser;

    private Date gmtModified;

    private String gmtModifiedUser;

    private Integer status;

    public WpxxInfo(Integer id, String billNo, String types, String name, String nos, String addr, String lng, String lat, String des, String photoPath, String synced, String lngGps, String latGps, String cjdw, String filepath, Date gmtCreate, String gmtCreateUser, Date gmtModified, String gmtModifiedUser, Integer status) {
        this.id = id;
        this.billNo = billNo;
        this.types = types;
        this.name = name;
        this.nos = nos;
        this.addr = addr;
        this.lng = lng;
        this.lat = lat;
        this.des = des;
        this.photoPath = photoPath;
        this.synced = synced;
        this.lngGps = lngGps;
        this.latGps = latGps;
        this.cjdw = cjdw;
        this.filepath = filepath;
        this.gmtCreate = gmtCreate;
        this.gmtCreateUser = gmtCreateUser;
        this.gmtModified = gmtModified;
        this.gmtModifiedUser = gmtModifiedUser;
        this.status = status;
    }

    public WpxxInfo() {
        super();
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getBillNo() {
        return billNo;
    }

    public void setBillNo(String billNo) {
        this.billNo = billNo == null ? null : billNo.trim();
    }

    public String getTypes() {
        return types;
    }

    public void setTypes(String types) {
        this.types = types == null ? null : types.trim();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getNos() {
        return nos;
    }

    public void setNos(String nos) {
        this.nos = nos == null ? null : nos.trim();
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr == null ? null : addr.trim();
    }

    public String getLng() {
        return lng;
    }

    public void setLng(String lng) {
        this.lng = lng == null ? null : lng.trim();
    }

    public String getLat() {
        return lat;
    }

    public void setLat(String lat) {
        this.lat = lat == null ? null : lat.trim();
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des == null ? null : des.trim();
    }

    public String getPhotoPath() {
        return photoPath;
    }

    public void setPhotoPath(String photoPath) {
        this.photoPath = photoPath == null ? null : photoPath.trim();
    }

    public String getSynced() {
        return synced;
    }

    public void setSynced(String synced) {
        this.synced = synced == null ? null : synced.trim();
    }

    public String getLngGps() {
        return lngGps;
    }

    public void setLngGps(String lngGps) {
        this.lngGps = lngGps == null ? null : lngGps.trim();
    }

    public String getLatGps() {
        return latGps;
    }

    public void setLatGps(String latGps) {
        this.latGps = latGps == null ? null : latGps.trim();
    }

    public String getCjdw() {
        return cjdw;
    }

    public void setCjdw(String cjdw) {
        this.cjdw = cjdw == null ? null : cjdw.trim();
    }

    public String getFilepath() {
        return filepath;
    }

    public void setFilepath(String filepath) {
        this.filepath = filepath == null ? null : filepath.trim();
    }

    public Date getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(Date gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    public String getGmtCreateUser() {
        return gmtCreateUser;
    }

    public void setGmtCreateUser(String gmtCreateUser) {
        this.gmtCreateUser = gmtCreateUser == null ? null : gmtCreateUser.trim();
    }

    public Date getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(Date gmtModified) {
        this.gmtModified = gmtModified;
    }

    public String getGmtModifiedUser() {
        return gmtModifiedUser;
    }

    public void setGmtModifiedUser(String gmtModifiedUser) {
        this.gmtModifiedUser = gmtModifiedUser == null ? null : gmtModifiedUser.trim();
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public static WpxxInfo toBean(String object){
        try{
            WpxxInfo info = new WpxxInfo();
            JSONObject record = JSON.parseObject(object);
            info.setSynced("0");
            info.setTypes(record.getString("wplx"));
            info.setName(record.getString("wpmc"));
            info.setNos(record.getString("xghm"));
            info.setAddr(record.getString("address"));
            info.setDes(record.getString("bzxx"));
            info.setLat(record.getString("latitude"));
            info.setLng(record.getString("longitude"));

            info.setGmtCreate(record.getDate("createdAt"));
            info.setGmtCreateUser(record.getString("createdBy"));
            //info.setGmtModified(record.getDate("modifiedAt"));
            info.setGmtModified(new Date());
            info.setGmtModifiedUser(record.getString("modifiedBy"));

            //概貌照片
            String filePaths = "";
            JSONArray list = record.getJSONArray("pictureList");
            for (int i = 0; i < list.size(); i++) {
                JSONObject dataObj = list.getJSONObject(i);
                filePaths += dataObj.getString("path") +",";
            }
            info.setPhotoPath(filePaths);
            return info;
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return null;
    }
}